package com.training.web.controller.comtent;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.training.common.annotation.Log;
import com.training.common.core.controller.BaseController;
import com.training.common.core.domain.AjaxResult;
import com.training.common.enums.BusinessType;
import com.training.content.domain.ExamSubject;
import com.training.content.service.IExamSubjectService;
import com.training.common.utils.poi.ExcelUtil;
import com.training.common.core.page.TableDataInfo;

/**
 * 试卷题目Controller
 * 
 * @author training
 * @date 2021-10-25
 */
@RestController
@RequestMapping("/exam/subject")
public class ExamSubjectController extends BaseController
{
    @Autowired
    private IExamSubjectService examSubjectService;

    /**
     * 查询试卷题目列表
     */
    @PreAuthorize("@ss.hasPermi('exam:subject:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExamSubject examSubject)
    {
        startPage();
        List<ExamSubject> list = examSubjectService.selectExamSubjectList(examSubject);
        return getDataTable(list);
    }

    /**
     * 导出试卷题目列表
     */
    @PreAuthorize("@ss.hasPermi('exam:subject:export')")
    @Log(title = "试卷题目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ExamSubject examSubject)
    {
        List<ExamSubject> list = examSubjectService.selectExamSubjectList(examSubject);
        ExcelUtil<ExamSubject> util = new ExcelUtil<ExamSubject>(ExamSubject.class);
        return util.exportExcel(list, "试卷题目数据");
    }

    /**
     * 获取试卷题目详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:subject:query')")
    @GetMapping(value = "/{subjectId}")
    public AjaxResult getInfo(@PathVariable("subjectId") Long subjectId)
    {
        return AjaxResult.success(examSubjectService.selectExamSubjectBySubjectId(subjectId));
    }

    /**
     * 新增试卷题目
     */
    @PreAuthorize("@ss.hasPermi('exam:subject:add')")
    @Log(title = "试卷题目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamSubject examSubject)
    {
        return toAjax(examSubjectService.insertExamSubject(examSubject));
    }

    /**
     * 修改试卷题目
     */
    @PreAuthorize("@ss.hasPermi('exam:subject:edit')")
    @Log(title = "试卷题目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamSubject examSubject)
    {
        return toAjax(examSubjectService.updateExamSubject(examSubject));
    }

    /**
     * 删除试卷题目
     */
    @PreAuthorize("@ss.hasPermi('exam:subject:remove')")
    @Log(title = "试卷题目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{subjectIds}")
    public AjaxResult remove(@PathVariable Long[] subjectIds)
    {
        return toAjax(examSubjectService.deleteExamSubjectBySubjectIds(subjectIds));
    }
}
